-
Couldn't load subscription status.
- Fork 462
Add 'SwiftWarningControl' library for source-level lexical warning group behavior settings #3174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
becf8ff to
463a525
Compare
463a525 to
150b44d
Compare
|
@swift-ci test |
|
@swift-ci test Windows platform |
Sources/SwiftWarningControl/SyntaxProtocol+WarningControl.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftWarningControl/SyntaxProtocol+WarningControl.swift
Outdated
Show resolved
Hide resolved
6a783d7 to
8d6686c
Compare
|
Thanks for the detailed feedback so far, @ahoppen ! |
8d6686c to
21ebbba
Compare
|
@swift-ci test |
1 similar comment
|
@swift-ci test |
Sources/SwiftWarningControl/SyntaxProtocol+WarningControl.swift
Outdated
Show resolved
Hide resolved
f67dccb to
89d0342
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two small comment
…oup behavior settings This library provides support for a mechanism to control the behavior of specific diagnostic groups for a given declaration's lexical scope with the `@warn` attribute. The syntax tree and its parser do not reason about warning group controls. The syntax tree produced by the parser reprsents the `@warn` attribute in a generic fashion, as it would any other basic attribute on a declaration. The per-declaration nature of the attribute means that for any given declaration's lexical scope, the behavior of a given diagnosic group can be queried by checking for the presence of this attribute in its parent declaration scope. The `SwiftWarningControl` library provides a utility to determine, for a given source location and diagnostic group identifier, whether or not its behavior is affected by an `@warn` attribute of any of its parent declaration scope. This utility relies on constructing a warning control tree data structure to represent all warning control lexical scopes in a given source file. This data structure all of the `@warn` diagnostic group behavior controls within the given syntax node, indicating each group's active behavior at a given position. For example, given code like the following: ``` 1: @warn(Deprecate, as: error) 2: func foo() { 3: let a = dep 4: @warn(Deprecate, as: warning) 5: func bar() { 6: let b = dep 7: @warn(Deprecate, as: ignored) 8: func baz() { 9: let c = dep 10: } 11: @warn(Deprecate, as: error) 12: @warn(OtherGroup, as: ignored) 13: func qux() { 14: let d = dep 15: @warn(SomeOtherGroup, as: warning) 16: func corge() { 17: let e = dep 18: } 19: } 20: } 21: } 22: func grault() { 23: let f = dep 24: } ``` the result will be: ``` - [`Deprecate`:`error`] region within `foo` lexical scope (lines 1-22) - [`Deprecate`:`warning`] region within `bar` lexical scope (lines 4-20) - [`Deprecate`:`ignored`] region within `baz` lexical scope (lines 7-10) - [`Deprecate`:`error`, `OtherGroup`:`ignored`] region within `qux` lexical scope (lines 12-19) - [`SomeOtherGroup`:`warning`] region within `corge` lexical scope (lines 15-18) ``` The data structure represents these regions and their nesting relationships as an interval tree where interval nodes can only be nested or disjoint, and where a given interval corresponds to a diagnostic control region for one or more diagnostic group, with a behavior specifier for each. Intervals cannot partially overlap, and each node's child intervals are always kept sorted. The tree has multiple top-level nodes (roots) representing file-level warning control regions. Once the tree is computed, lookup of a diagnostic group behavior at a given position is performed by recursively descending into the child node containing the given position (located with a binary search of child nodes of a given parent node). Once the position's depth in the interval tree is reached, we walk back the traversal until we find the first containing region which specifies warning behavior control for the given diagnostic group id.
89d0342 to
a92c94c
Compare
|
@swift-ci test |
|
@swift-ci test Windows platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my side
This library provides support for a mechanism to control the behavior of specific diagnostic groups for a given declaration's lexical scope with the
@warnattribute.The syntax tree and its parser do not reason about warning group controls. The syntax tree produced by the parser reprsents the
@warnattribute in a generic fashion, as it would any other basic attribute on a declaration. The per-declaration nature of the attribute means that for any given declaration's lexical scope, the behavior of a given diagnosic group can be queried by checking for the presence of this attribute in its parent declaration scope.The
SwiftWarningControllibrary provides a utility to determine, for a given source location and diagnostic group identifier, whether or not its behavior is affected by an@warnattribute of any of its parent declaration scope.This utility relies on constructing a warning control tree data structure to represent all warning control lexical scopes in a given source file. This data structure all of the
@warndiagnostic group behavior controls within the given syntax node, indicating each group's active behavior at a given position.For example, given code like the following:
the result will be:
The data structure represents these regions and their nesting relationships as an interval tree where interval nodes can only be nested or disjoint, and where a given interval corresponds to a diagnostic control region for one or more diagnostic group, with a behavior specifier for each.
Intervals cannot partially overlap, and each node's child intervals are always kept sorted. The tree has a single top-level node (root) representing file-level scope.
Once the tree is computed, lookup of a diagnostic group behavior at a given position is performed by recursively descending into the child node containing the given position (located with a binary search of child nodes of a given parent node). Once the position's depth in the interval tree is reached, we walk back the traversal until we find the first containing region which specifies warning behavior control for the given diagnostic group id.